import base from '@/config/base.js'
export default {
    data() {
        return {
            share: {
                // 转发的标题 （默认标题）
                title: '一卡在手，说走就走',
                // 默认是当前页面，必须是以‘/’开头的完整路径
                path: '',
                //自定义图片路径，可以是本地文件路径、代码包文件路径或者网络图片路径，
                //支持PNG及JPG，不传入 imageUrl 则使用默认截图。显示图片长宽比是 5:4
                imageUrl: base.baseUrl+'assets/img/web/share.jpg'
            }
        }
    },

     onLoad(option) {
        if(option.invitation){
			uni.setStorageSync('invitation',option.invitation)
		}
     },
    
    // 发送给朋友
    onShareAppMessage(res) {
		let that = this;
        // 来自页面内的按钮的转发
        if (res.from == 'button') {
            console.log("按钮转发--配置");
        }
        // 获取加载的页面
        let pages = getCurrentPages(),
            // 获取当前页面的对象
            view = pages[pages.length - 1];
        this.share.path = `/${view.route}`;
		let tpath = this.share.path;
		this.share.path += '?invitation='+uni.getStorageSync('userinfo').invitation
        switch(tpath){
			case '/pages/goods/goods':
				this.share.path += '&goodsId='+that.$scope.options.goodsId
			break;
			case '/pages/article/info':
				this.share.path += '&articleId='+that.$scope.options.articleId
			break;
			case '/pages/tourismLife/lifeInfo':
				this.share.path += '&id='+that.$scope.options.id
			break;
		}
        //转发参数
        return this.share;
    },
    //分享到朋友圈
    onShareTimeline(res) {
        // 获取加载的页面
        let pages = getCurrentPages(),
            // 获取当前页面的对象
            view = pages[pages.length - 1];
        this.share.path = `/${view.route}`;
		
		
		let tpath = this.share.path;
		this.share.path += '?invitation='+uni.getStorageSync('userinfo').invitation
		switch(tpath){
			case '/pages/goods/goods':
				this.share.path += '&goodsId='+that.$scope.options.goodsId
			break;
			case '/pages/article/info':
				this.share.path += '&articleId='+that.$scope.options.articleId
			break;
			case '/pages/tourismLife/lifeInfo':
				this.share.path += '&id='+that.$scope.options.id
			break;
		}
        //转发参数
        return this.share;
    },
	
}